<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="__TMPL__Public/assets/book_static/css/base.css" />
<link rel="stylesheet" href="__TMPL__Public/assets/book_static/css/info-mgt.css" />
<link rel="stylesheet" href="__TMPL__Public/assets/book_static/css/WdatePicker.css" />
<link rel="stylesheet" href="__TMPL__Public/assets/layui/css/layui.css">
<link rel="stylesheet" href="__TMPL__Public/assets/book_static/css/pager.css">
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/jquery.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/layui/layui.js"></script>
<title>图书库存管理系统</title>
</head>

<body>
<div class="title"><h2>图书出库</h2></div>
<div class="query">
	<div class="query-conditions ue-clear">
        <div class="conditions staff ue-clear" style="width:850px;">
			<form id="searchform" target="_self" method="GET" action="index.php">
				<input type="hidden" name="m" value="index">
				<input type="hidden" name="a" value="chuku">
				<div class="conditions time ue-clear" style="line-height:38px;margin-right: 40px;width:auto;">
					<label>ISBN：</label>
					<input type="text" style="line-height: 36px;height: 36px;width:120px;" name="isbn" id="isbn" placeholder="直接输入ISBN编号" value="{$data.isbn}">
				</div>
				<button type="button" class="layui-btn layui-btn-normal" id="test12" style="margin-top: 5px;float:left;">查询</button>
				
				<div class="conditions time ue-clear" style="line-height:38px;margin-right:10px;width:auto;">
					<label style="margin-left:20px;">出库数量：</label>
					<input type="text" style="line-height: 36px;height: 36px;width:40px;" name="booknum" id="booknum" placeholder="" value="">
				</div>	
				<button type="button" class="layui-btn layui-btn" id="test13" style="margin-top: 5px;float:left;">批量填写</button>
				<button type="button" class="layui-btn layui-btn-danger" id="test14" style="margin-top: 5px;float:left;">出货</button>
			</form>
        </div>
		
		
		
		<div class="conditions staff ue-clear" style="width: auto;float:right;">
			<div class="layui-upload">
				<button type="button" class="layui-btn layui-btn-normal" id="test8"><i class="layui-icon">&#xe67c;</i>选择文件</button>
				<button type="button" class="layui-btn" id="test9">上传并导入出库信息</button>
				<a href="/data/chuku.xls">
					<button type="button" class="layui-btn layui-btn-danger" id="test7"><i class="layui-icon">&#xe61e;</i>下载出库模板表</button>
				</a>
				<!--
				<a href="javascript:chuku_one();">
					<button type="button" class="layui-btn layui-btn-normal" id="test10"><i class="layui-icon">&#xe609;</i>快速出库</button>
				</a>
				-->
			</div>
		</div>
				
		
    </div>
	
		

</div>

<div class="table-box">
	<table>
    	<thead>
        	<tr>
            	<th class="num">序号</th>
                <th class="name">ISBN</th>
                <th class="node">书名</th>
                <th class="name">数量<span>(本)</span></th>
                <th class="time">价格</th>
                <th class="time">位置</th>
                <th class="time" style="width:60px;">出库数量</th>
            </tr>
        </thead>
        <tbody>
		<form id="chukuaction" target="_self" method="POST" action="index.php?m=index&a=chukuaction">
			<foreach name="data.list" item="vo" key="k">
        	<tr class="{$vo.id}">
            	<td class="num">{$vo.id}<input type="hidden" name="idarr[]" value="{$vo.id}"></td>
                <td class="name isbn" vi="{$vo.bookname}">{$vo.isbn}</td>
                <td class="node bookname" style="width:300px">
				<if condition="$vo.bookname neq ''">
					{$vo.bookname}
				<else/>
					--
				</if>
				</td>
                <td class="name booknumlist">{$vo.booknum}</td>
                <td class="time price">{$vo.price}</td>
                <td class="time price">{$vo.location}</td>
				<td class="time price"  style="width:60px;">
					<input  style="width:50px;height:18px;" type="text" name="booknumarr[]" class="booknum" value="">
				</td>
            </tr>
			</foreach>
		</form>
        </tbody>
    </table>
</div>

<div class="pxofy">当前合计&nbsp;{$data.count}&nbsp;条数据，共{$data.total}本。

</div>
<div class="page-control ue-clear"></div>


</body>
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/jquery.page.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/common.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/WdatePicker.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/jquery.pagination.js"></script>

<script type="text/javascript">
function piliang(booknum){
	booknum = parseInt(booknum);
	if( booknum>{$data.total} ){
		layer.msg('出库数量大于库存！', {icon: 2,shade:0.5});
		return;
	}
	$(".booknum").val("");
	$("#booknum").val("");
	
	$(".booknumlist").each(function(){
		var thisbooknum = $(this).text();
		if( thisbooknum >=booknum ){
			$(this).parent("tr").find(".booknum").val(booknum);
			return false;
		}else{
			booknum = booknum - thisbooknum;
			$(this).parent("tr").find(".booknum").val(thisbooknum);
		}
	});
}

$("#test12").click(function(){
	var isbn = $("#isbn").val();
	if(isbn==""){
		layer.msg('请填写ISBN！', {icon: 2,shade:0.5});return;
		return;
	}
	$("#searchform").submit();
})

$("#test13").click(function(){
	var booknum = $("#booknum").val();
	if(booknum==""){
		layer.msg('请填写批量出库数量！', {icon: 2,shade:0.5});return;
		return;
	}
	piliang(booknum);
})

$("#test14").click(function(){
	var checkbooknum = 0;
	$(".booknumlist").each(function(){
		thisbooknum = $(this).parent("tr").find(".booknum").val();
		checkbooknum = checkbooknum + parseInt(thisbooknum);
	});
	if( checkbooknum==0 ){
		layer.msg('出库数量不能为0！', {icon: 2,shade:0.5});
		return;
	}
	if( checkbooknum>{$data.total} ){
		layer.msg('出库数量大于库存！', {icon: 2,shade:0.5});
		return;
	}
	$("#chukuaction").submit();
})



$(".select-title").on("click",function(){
	$(".select-list").hide();
	$(this).siblings($(".select-list")).show();
	return false;
})
$(".select-list").on("click","li",function(){
	var txt = $(this).text();
	$(this).parent($(".select-list")).siblings($(".select-title")).find("span").text(txt);
})



$("tbody").find("tr:odd").css("backgroundColor","#eff6fa");

layui.use('upload', function(){
	var $ = layui.jquery
	,upload = layui.upload;
	upload.render({
		elem: '#test8'
		,url: "{:U('index/chukuup')}"
		,accept: 'file'
		,auto: false
		//,multiple: true
		,bindAction: '#test9'
		,before: function(res){
			layer.load(3); //上传loading
		}
		,done: function(res){
			if(res.state=="fail"){
				layer.closeAll('loading');
				layer.msg('导入失败，'+res.message, {time: 5000, icon:5,shade: 0.7});
			}else{
				layer.closeAll('loading');
				window.location.href="{:U('index/chuku_pl')}";
			}
		},error: function(index, upload){
			layer.closeAll('loading');
		}
	});
});


function getIsbn(isbn,that){
	var url = "{:U('index/updateisbninfo')}&isbn="+isbn;
	$.getJSON(url,function(result){
		if(result.status==0){
			return false;
		}else{
			var imgstr = '<img src="'+result.image+'" width="50" style="padding:8px;">'+result.title;
			if(typeof(result.title)!="undefined"){
				$(that).closest('tr').find("td.bookname").html(imgstr);
				$(that).closest('tr').find("td.price").html(result.price);
			}else{
				$(that).closest('tr').find("td.bookname").html("系统未获取到该书数据");
			}
		}
	});
}

$(document).ready(function(){
	var updatetime = 0;
	$(".isbn").each(function(i){
		var isbn = $(this).html();
		var bookname = $(this).attr("vi");
		if(isbn==''){
			return true;
		}
		if(bookname!=''){
			return true;
		}
		//getIsbn(isbn,this);
	})
});

function delsure(kucunid){
	if(kucunid==""){
		layer.msg('参数错误！', {icon: 2});return;
	}
	layer.confirm('是否确认删除该信息？', {
		icon: 3,
		btn: ['确认','取消'] //按钮
	}, function(){
		var url = "{:U('index/delchuku')}&chukuid="+kucunid;
		window.location.href=url;
	});
}

function chuku_one(){
	var index = layer.open({
		type: 2,
		title: false,
		closeBtn: 0, //不显示关闭按钮
		shade: [0.2],
		area: ['410px', '215px'],
		anim: 2,
		closeBtn:true,
		content: ["{:U('index/chuku_one')}", 'no'], //iframe的url，no代表不显示滚动条
	});
}
</script>
</html>
